package cn.itsource.pethome.org.service.impl;

import cn.itsource.pethome.basic.service.impl.BaseServiceImpl;
import cn.itsource.pethome.org.domain.Employee;
import cn.itsource.pethome.org.domain.Shop;
import cn.itsource.pethome.org.mapper.EmployeeMapper;
import cn.itsource.pethome.org.mapper.ShopMapper;
import cn.itsource.pethome.org.query.ShopQuery;
import cn.itsource.pethome.org.service.IShopService;
import cn.itsource.pethome.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ShopServiceImpl extends BaseServiceImpl<Shop> implements IShopService {

    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private ShopMapper shopMapper;

    @Override
    public void save(Shop shop) {
        //调用保存，先将其关联的employee存入t_employee，并返回主键
        employeeMapper.save(shop.getEmployee());
        //然后再保存到t_shop表中
        shopMapper.save(shop);
    }

    @Override
    @Transactional
    public void update(Shop shop) {
        //将shop表的state修改为-1 且将employee的state修改为-1
        Employee employee = employeeMapper.loadById(shop.getEmployee().getId());
        employee.setState(-1);
        employeeMapper.update(employee);

        shop.setState(-1);
        shopMapper.update(shop);
    }
}
